#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Filename: bug_template.py
# Author: ChenChangSong
# Date: 2025-11-03

"""
功能描述: bug模板
https://open.tapd.cn/document/api-doc/API%E6%96%87%E6%A1%A3/api_reference/bug/get_bug_template_list.html
"""

import sys
from pathlib import Path
sys.path.append(str(Path(__file__).resolve().parent.parent.parent))
from comm.common_code import *

def get_bug_template():
    """获取bug模板"""
    excel_data = get_excel_data()
    url = f"https://api.tapd.cn/bugs/template_list?workspace_id={excel_data['项目ID']}&access_token={excel_data['access_token']}"

    payload={}
    headers = {}

    response_code, response = api_request(method="GET", url=url, headers=headers, data=payload)
    if response_code == 200:
        template_dit ={}
        template_data_list = response['data']
        for template_data in template_data_list:
            template_id = template_data['WorkitemTemplate']['id']
            template_name = template_data['WorkitemTemplate']['name']
            template_dit[template_id] = template_name
        logger.info(template_dit)
        return template_dit
    else:
        logger.error(f"获取bug模板失败 - 状态码: {response_code}")
        logger.error(f"错误响应内容: {response.text}")
        return None
    
if __name__ == "__main__":
    get_bug_template()